(function() {
	var _num = 20;
	var _page = 0;
	var _type;

	function on_cancel_ach_success(vm, result) {
		vm.removeFromArray();
		_load_achs_page(_type, _num, _page);
	};

	function _load_achs_page(type, num, page) {
		//状态标识
		if (type === "未支付") {
			App.set("$Cache.user.order.achs.type", "未支付订单");
			App.set("typeNum", 2);
		} else {
			App.set("$Cache.user.order.achs.type", "所有订单");
			App.set("typeNum", 1);
		}

		coAjax.get(appConfig.user.achs_with_type_and_page_info, {
			num: num,
			page: page,
			type: type
		}, function(result) {
			var info = result.result;
			jSouper.forEach(info.achs, function(ach) {
				$Event = ach.$Event || (ach.$Event = {});
				$Event.cancel_ach_success = on_cancel_ach_success;
			});
			console.log("user.achs", info.achs);
			App.set("user.achs", info.achs);
			page_info = {
				total_num: info.total_num,
				total_page: info.total_page,
				page: info.page,
				num: info.num
			};
			page_info._number_list = [];
			page_info._number_list.length = info.total_page;
			App.set("$Cache.user.order.achs.page_info", page_info);
		}, function(errorCode, xhr, errorMsg) {
			console.log(errorCode);
			alert("error", errorMsg);
		});
	}


	//分页功能
	Path.on(["/user/__basename__.html", "/user/"], function(_current_location) {
		var queryString = _current_location.query;
		_num = queryString.get("num") || _num;
		_page = queryString.get("page") || _page;
		_type = queryString.get("type") || _type;
		_load_achs_page(_type, _num, _page);
	});
}());